balance = int(input("请输入您的支付宝余额："))
products = [("iPhone 12 Mini", 699),
            ("iPhone 12", 799),
            ("iPhone 12 Pro", 999),
            ("iPhone 12 Pro Max", 1099)]
cart = {}

while True:
    # 打印商品目录
    for product in products:
        print(products.index(product) + 1, product[0], product[1])
    selection = int(input("输入商品编号进行购买："))
    # 判断编号输入正确与否
    if 1 <= selection < len(products) + 1:
        count = int(input("输入购买数量："))
        # 判断余额是否足以购买
        if balance >= products[selection - 1][1] * count:
            # 记录商品名称及购买数量
            cart.update({products[selection - 1][0]: count})
            # 更新余额
            balance -= products[selection - 1][1] * count
            print("购买成功，支付宝余额剩余{}。".format(balance))
            continueShopping = input("是否继续购物：")
            if continueShopping == "否":
                # 输出购买详情及最终余额
                print("您共购买了", end="")
                for key, value in cart.items():
                    print("{}台{}；".format(value, key), end="")
                print("支付宝余额剩余{}。".format(balance))
                break
        else:
            print("余额不足。")
            continueShopping = input("是否继续购物：")
            if continueShopping == "否":
                # 输出购买详情及最终余额
                print("您共购买了", end="")
                for key, value in cart.items():
                    print("{}台{}；".format(value, key), end="")
                print("支付宝余额剩余{}。".format(balance))
                break
    else:
        print("无此商品，请重新选择。", "\n")